home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / codecvt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  12.2 KB  |  362 lines

  1. #ifndef __STD_CODECVT__
  2. #define __STD_CODECVT__
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * codecvt - Declarations for the Standard Library code conversion facet
  8.  *
  9.  *
  10.  ***************************************************************************
  11.  *
  12.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  13.  * ALL RIGHTS RESERVED *
  14.  * The software and information contained herein are proprietary to, and
  15.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  16.  * intends to preserve as trade secrets such software and information.
  17.  * This software is furnished pursuant to a written license agreement and
  18.  * may be used, copied, transmitted, and stored only in accordance with
  19.  * the terms of such license and with the inclusion of the above copyright
  20.  * notice.  This software and information or any other copies thereof may
  21.  * not be provided or otherwise made available to any other person.
  22.  *
  23.  * Notwithstanding any other lease or license that may pertain to, or
  24.  * accompany the delivery of, this computer software and information, the
  25.  * rights of the Government regarding its use, reproduction and disclosure
  26.  * are as set forth in Section 52.227-19 of the FARS Computer
  27.  * Software-Restricted Rights clause.
  28.  *
  29.  * Use, duplication, or disclosure by the Government is subject to
  30.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  31.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  32.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  33.  * P.O. Box 2328, Corvallis, Oregon 97339.
  34.  *
  35.  * This computer software and information is distributed with "restricted
  36.  * rights."  Use, duplication or disclosure is subject to restrictions as
  37.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  38.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  39.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  40.  * then the "Alternate III" clause applies.
  41.  *
  42.  **************************************************************************/
  43.  
  44.  
  45. #ifndef __STD_RWLOCALE__
  46. #include "rw/rwlocale.h"
  47. #endif
  48.  
  49. #ifndef __STD_LIMITS
  50. #include <limits>
  51. #endif
  52.  
  53. #ifndef _RWSTD_NO_NAMESPACE
  54. namespace std {
  55. #endif
  56.  
  57. struct _RWSTDExport codecvt_base {
  58.   enum result { ok, partial, error, noconv };
  59. };
  60.  
  61. // ------------------------------------------------------
  62. // Codeset conversion facet -- codecvt<fromT,toT,stateT>.
  63. // ------------------------------------------------------
  64. template <class internT, class externT, class stateT>
  65. class _RWSTDExportTemplate codecvt;
  66.  
  67. _RWSTD_TEMPLATE
  68. class _RWSTDExport codecvt<char,char,mbstate_t>:
  69.     public locale::facet, public codecvt_base
  70. {
  71.  public:
  72.  
  73.   typedef char      extern_type;   
  74.   typedef char      intern_type;
  75.   typedef mbstate_t state_type;
  76.  
  77.   _EXPLICIT codecvt (size_t refs=0):
  78.       locale::facet(refs,locale::_rw_ctype_category) { }
  79.  
  80.   bool always_noconv() const _RWSTD_THROW_SPEC_NULL
  81.     { return do_always_noconv(); }
  82.  
  83.   int encoding() const _RWSTD_THROW_SPEC_NULL
  84.     { return do_encoding(); }
  85.  
  86.   result out (mbstate_t& state,
  87.       const char* from, const char* from_end, const char*& from_next,
  88.       char* to, char* to_limit, char*& to_next) const
  89.     { return do_out(state,from,from_end,from_next,to,to_limit,to_next); }
  90.  
  91.  
  92.   result in(mbstate_t& state,
  93.       const char* from, const char* from_end, const char*& from_next,
  94.       char* to, char* to_limit, char*& to_next) const
  95.     { return do_in(state,from,from_end,from_next,to,to_limit,to_next); }
  96.  
  97.   int length (const mbstate_t& state, const char* from, const char* end,
  98.       size_t max) const { return do_length(state,from,end,max); }
  99.  
  100.   int max_length() const _RWSTD_THROW_SPEC_NULL
  101.     { return do_max_length(); }
  102.  
  103.   static locale::id _RWSTDExport id;
  104.  
  105.   // Rogue Wave extension:
  106.   typedef string internal_string_type;
  107.   typedef string external_string_type;
  108.   internal_string_type in (const external_string_type &s) const { return s; }
  109.   external_string_type out (const internal_string_type &s) const { return s; }
  110.  
  111.   // Implementation:
  112.   enum { facet_cat_ = locale::_rw_ctype_category, ok_implicit_ = 1 };
  113.  
  114.  protected:
  115.   virtual ~codecvt();
  116.  
  117.   virtual result do_out(mbstate_t& state,
  118.     const char* from, const char* from_end, const char*& from_next,
  119.           char* to, char* to_limit, char*& to_next) const;
  120.  
  121.   virtual result do_in(mbstate_t& state,
  122.     const char* from, const char* from_end, const char*& from_next,
  123.           char* to, char* to_limit, char*& to_next) const;
  124.  
  125.   virtual bool do_always_noconv() const _RWSTD_THROW_SPEC_NULL;
  126.  
  127.   virtual int do_encoding() const _RWSTD_THROW_SPEC_NULL;
  128.  
  129.   virtual int do_length (const mbstate_t&, const char* from, const char* end,
  130.       size_t max) const;
  131.  
  132.   virtual int do_max_length() const _RWSTD_THROW_SPEC_NULL;
  133.  
  134.  private:
  135.   #ifdef _RWSTD_NO_MEMBER_TEMPLATES
  136.   locale::id &get_id (void) const { return id; }
  137.   #endif
  138. };
  139.  
  140. #ifndef _RWSTD_NO_WIDE_CHAR
  141. _RWSTD_TEMPLATE
  142. class _RWSTDExport codecvt<wchar_t,char,mbstate_t>:
  143.     public locale::facet, public codecvt_base
  144. {
  145.  public:
  146.   typedef wchar_t intern_type;
  147.   typedef char    extern_type;
  148.   typedef mbstate_t state_type;
  149.  
  150.   _EXPLICIT codecvt (size_t refs=0):
  151.       locale::facet(refs,locale::_rw_ctype_category) { }
  152.  
  153.   bool always_noconv() const _RWSTD_THROW_SPEC_NULL
  154.     { return do_always_noconv(); }
  155.  
  156.   int encoding() const _RWSTD_THROW_SPEC_NULL
  157.     { return do_encoding(); }
  158.  
  159.   result out (mbstate_t& state,
  160.       const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
  161.       char* to, char* to_limit, char*& to_next) const
  162.     { return do_out(state,from,from_end,from_next,to,to_limit,to_next); }
  163.  
  164.   result in (mbstate_t& state,
  165.       const char* from, const char* from_end, const char*& from_next,
  166.       wchar_t* to, wchar_t* to_limit, wchar_t*& to_next) const
  167.     { return do_in(state,from,from_end,from_next,to,to_limit,to_next); }
  168.  
  169.   int length (const mbstate_t& state, const wchar_t* from, const wchar_t* end,
  170.       size_t max) const
  171.     { return do_length(state,from,end,max); }
  172.  
  173.   int max_length() const _RWSTD_THROW_SPEC_NULL
  174.     { return do_max_length(); }
  175.  
  176.   static locale::id _RWSTDExport id;
  177.  
  178.   // Rogue Wave extension:
  179.   typedef string external_string_type;
  180.   typedef wstring internal_string_type;
  181.   internal_string_type in (const external_string_type &s) const;
  182.   external_string_type out (const internal_string_type &s) const;
  183.  
  184.   // Implementation:
  185.   enum { facet_cat_ = locale::_rw_ctype_category, ok_implicit_ = 1 };
  186.  
  187.  protected:
  188.   virtual ~codecvt();
  189.  
  190.   virtual result do_out(mbstate_t& state,
  191.     const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
  192.           char* to, char* to_limit, char*& to_next) const;
  193.  
  194.   virtual result do_in(mbstate_t& state,
  195.     const char* from, const char* from_end, const char*& from_next,
  196.           wchar_t* to, wchar_t* to_limit, wchar_t*& to_next) const;
  197.  
  198.   virtual bool do_always_noconv() const _RWSTD_THROW_SPEC_NULL;
  199.  
  200.   virtual int do_encoding() const _RWSTD_THROW_SPEC_NULL;
  201.  
  202.   virtual int do_length (const mbstate_t&, const wchar_t* from,
  203.       const wchar_t* end, size_t max) const;
  204.  
  205.   virtual int do_max_length() const _RWSTD_THROW_SPEC_NULL;
  206.  
  207.  private:
  208.   #ifdef _RWSTD_NO_MEMBER_TEMPLATES
  209.   locale::id &get_id (void) const { return id; }
  210.   #endif
  211. };
  212.  
  213. #endif // _RWSTD_NO_WIDE_CHAR
  214.  
  215. template <class internT, class externT, class stateT>
  216. class _RWSTDExportTemplate codecvt: public locale::facet, public codecvt_base {
  217.  public:
  218.   typedef internT intern_type;
  219.   typedef externT extern_type;
  220.   typedef stateT state_type;
  221.  
  222.   _EXPLICIT codecvt (size_t refs=0): locale::facet(refs) { }
  223.  
  224.    result out (stateT& state,
  225.       const internT* from, const internT* from_end, const internT*& from_next,
  226.       externT* to, externT* to_limit, externT*& to_next) const
  227.     { return do_out(state,from,from_end,from_next,to,to_limit,to_next); }
  228.  
  229.   result in(stateT& state,
  230.       const externT* from, const externT* from_end, const externT*& from_next,
  231.       internT* to, internT* to_limit, internT*& to_next) const
  232.     { return do_in(state,from,from_end,from_next,to,to_limit,to_next); }
  233.  
  234.   bool always_noconv() const _RWSTD_THROW_SPEC_NULL
  235.     { return do_always_noconv(); }
  236.  
  237.   int encoding() const _RWSTD_THROW_SPEC_NULL
  238.     { return do_encoding(); }
  239.  
  240.   int length (const stateT& state, const internT* from, const internT* end,
  241.       size_t max) const
  242.     { return do_length(state,from,end,max); }
  243.  
  244.   int max_length() const _RWSTD_THROW_SPEC_NULL
  245.     { return do_max_length(); }
  246.  
  247.   static locale::id _RWSTDExport id;
  248.  
  249.   // Rogue Wave extension:
  250.   typedef basic_string<externT,char_traits<externT>,allocator<externT> >
  251.       external_string_type;
  252.   typedef basic_string<internT,char_traits<internT>,allocator<internT> >
  253.       internal_string_type;
  254.   internal_string_type in (const external_string_type &s) const;
  255.   external_string_type out (const internal_string_type &s) const;
  256.  
  257.   // Implementation:
  258.   enum { facet_cat_ = locale::ctype, ok_implicit_ = 1 };
  259.  
  260.  protected:
  261.   virtual ~codecvt();
  262.  
  263.   virtual result do_out(stateT& state,
  264.     const internT* from, const internT* from_end, const internT*& from_next,
  265.           externT* to, externT* to_limit, externT*& to_next) const;
  266.  
  267.   virtual result do_in(stateT& state,
  268.     const externT* from, const externT* from_end, const externT*& from_next,
  269.           internT* to, internT* to_limit, internT*& to_next) const;
  270.  
  271.  
  272.   virtual bool do_always_noconv() const _RWSTD_THROW_SPEC_NULL;
  273.   virtual int do_encoding() const _RWSTD_THROW_SPEC_NULL;
  274.   virtual int do_length (const stateT&, const internT* from, const internT* end,
  275.       size_t max) const;
  276.   virtual int do_max_length() const _RWSTD_THROW_SPEC_NULL;
  277.  
  278.  private:
  279.   #ifdef _RWSTD_NO_MEMBER_TEMPLATES
  280.   locale::id &get_id (void) const { return id; }
  281.   #endif
  282. };
  283.  
  284. template <class internT, class externT, class stateT>
  285. class _RWSTDExport codecvt_byname: public codecvt<internT,externT,stateT> {
  286.  public:
  287.   
  288.   typedef internT intern_type;
  289.   typedef externT extern_type;
  290.   typedef stateT state_type; 
  291.  
  292.   _EXPLICIT codecvt_byname (const char*, size_t refs=0);
  293.  
  294.  protected:
  295.   virtual ~codecvt_byname();
  296.  
  297.   virtual codecvt_base::result do_out(stateT&, 
  298.           const internT*, const internT*, const internT*&,
  299.           externT*, externT*, externT*&) const;
  300.  
  301.   virtual codecvt_base::result do_in(stateT&,
  302.     const externT*, const externT*, const externT*&,
  303.           internT*, internT*, internT*&) const;
  304.  
  305.  
  306.   virtual bool do_always_noconv () const _RWSTD_THROW_SPEC_NULL;
  307.  
  308. // Virtual member functions inherited from codecvt<,,>:
  309. // virtual int do_length (const stateT &state, const fromT* from,
  310. //     const fromT* end, size_t max) const;
  311. // virtual int do_max_length() const _RWSTD_THROW_SPEC_NULL;
  312. };
  313.  
  314.  
  315. // ----------------------------------------------------------------------
  316. // Codeset conversion member templates: codecvt_byname<fromT,toT,stateT>
  317. // ----------------------------------------------------------------------
  318.  
  319. template <class internT, class externT, class stateT>
  320. codecvt_byname<internT,externT,stateT>::codecvt_byname (const char*, size_t refs):
  321.     codecvt<internT,externT,stateT>(refs)
  322. { }
  323.  
  324. template <class internT, class externT, class stateT>
  325. codecvt_byname<internT,externT, stateT>::~codecvt_byname()
  326. { }
  327.  
  328.  
  329. template <class internT, class externT, class stateT>
  330. codecvt_base::result 
  331. codecvt_byname<internT,externT, stateT>::do_out(stateT&,
  332.     const internT*, const internT*, const internT*&,
  333.           externT*, externT*, externT*&) const
  334. { return codecvt_base::error; }
  335.  
  336.  
  337.  
  338. template <class internT, class externT, class stateT>
  339. codecvt_base::result
  340. codecvt_byname<internT,externT, stateT>::do_in(stateT&,
  341.     const externT*, const externT*, const externT*&,
  342.           internT*, internT*, internT*&) const
  343. { return codecvt_base::error; }
  344.  
  345. template <class internT, class externT, class stateT>
  346. bool codecvt_byname<internT,externT,stateT>::do_always_noconv () const
  347.     _RWSTD_THROW_SPEC_NULL
  348. {
  349.   return false;
  350. }
  351.  
  352. #ifndef _RWSTD_NO_NAMESPACE
  353. }
  354. #endif
  355.  
  356. #ifdef _RWSTD_COMPILE_INSTANTIATE
  357. #include <rw/codecvt.cc>
  358. #endif
  359.  
  360. #pragma option pop
  361. #endif // __STD_CODECVT__
  362.